#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int pointa = 0;
        int pointb = 0;
        int res = 0;
        while(pointb < prices.size())
        {
            if((pointb < prices.size() - 1) && (prices[pointb] <= prices[pointb+1]))
            {
                ++pointb;
            }
            else
            {
                res += prices[pointb] - prices[pointa];
                pointa = pointb + 1;
                pointb = pointa;
            }
        }
        return res;
    }
};